Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 4 - Commands / Command Definitions


Launch application command

If an application is not already running, sending it a Launch command launches it without sending a Run command. (If the application is already running, the Launch command has no effect.) This allows an application
to open without performing its usual startup procedures, such as opening a new window or, in the case of a script application, running the script.

SYNTAX
launch [ referenceToApplication ]
PARAMETER
referenceToApplication
A reference of the form application nameString (see "Notes"). This parameter is optional if the Launch command is used within an appropriate Tell statement.
Class: Reference
RESULT
None

EXAMPLES
launch application "Scriptable Text Editor"tell application "Scriptable Text Editor"   launch
end tell
NOTES
To specify the name (nameString) of an application to launch, use a string of the form "Disk:Folder1:Folder2:...:ApplicationName"; for details, see "References to Applications," which begins on page 146. You can also specify a string with only an application name ("ApplicationName"). In this case, AppleScript attempts to find the application in the current directory.

AppleScript sends an implicit Run command whenever it begins to execute a Tell statement whose target is an application that is not already open. This
can cause problems with applications such as the Scriptable Text Editor that normally perform specific tasks on startup, such as opening a new window. Here's an example:

tell application "Scriptable Text Editor"   open file "Hard Disk:Status Report"end tell
Before AppleScript opens the file Status Report, it sends an implicit Run command to Scriptable Text Editor. If the application is not already open,
the Run command causes Scriptable Text Editor not only to launch but also
to perform its usual startup tasks, including opening an untitled window. Therefore, running this script opens two windows: an untitled window and
a window for the file Status Report.

If you don't want AppleScript to send an implicit Run command when it launches an application as the result of a Tell statement, use the Launch command explicitly at the beginning of the statement:

tell application "Scriptable Text Editor"   launch
   open file "Hard Disk:Status Report"end tell
In this case, AppleScript launches the application without sending it a Run command, and the application opens only a window for the requested document.

For similar reasons, it is sometimes important to use the Launch command before sending the Run command to a script application. For more information, see "Calling a Script Application," which begins on page 251. For information about Run handlers, see "Run Handlers," which begins on page 243.

Although the target of a Launch command is always an application, it is actually handled by the Finder. Unlike the other application commands defined in this chapter, it doesn't need to be explicitly supported by applications and doesn't appear in any application's dictionary.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996